var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), e = require("../../../@babel/runtime/helpers/asyncToGenerator"), a = require("../../../@babel/runtime/helpers/defineProperty"), i = getApp(), o = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ o ],
    data: {
        active: 0,
        codeShow: !1,
        codeText: "",
        pictureShow: !1,
        pictureList: [],
        titleArr: [ {
            code: "waitWorker",
            name: "抢单大厅"
        }, {
            code: "all",
            name: "全部订单"
        }, {
            code: "waitTake",
            name: "待取货订单"
        }, {
            code: "waitDeliveryPay",
            name: "待到付订单"
        }, {
            code: "waitInstall",
            name: "待安装订单"
        }, {
            code: "refund",
            name: "售后订单"
        }, {
            code: "isFinish",
            name: "已完成订单"
        } ],
        location: {},
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        listData: [],
        networkLoading: !1,
        _order_id: 0,
        takeCodeImageUrl: "",
        custom_name: ""
    },
    setCodeShow: function() {
        this.setData({
            codeShow: !this.data.codeShow
        });
    },
    setPictureShow: function() {
        this.setData({
            pictureShow: !this.data.pictureShow
        });
    },
    makePhoneCall: function(t) {
        var e = t.currentTarget.dataset.mobile;
        wx.makePhoneCall({
            phoneNumber: e
        });
    },
    openLocation: function(t) {
        var e = t.currentTarget.dataset.item;
        wx.openLocation({
            latitude: Number(e.latitude),
            longitude: Number(e.longitude)
        });
    },
    onLoad: function(t) {
        var e = this;
        t.status && this.setData({
            active: Number(t.status)
        }), this._getLocation(function(t, a) {
            e.setData({
                "location.latitude": a.lat,
                "location.longitude": a.lng,
                "location.address": t.address
            }), e.getListData();
        });
    },
    initData: function() {
        this.setData({
            page: 1,
            total_page: 0,
            isLoadMore: !0,
            networkLoading: !1
        });
    },
    getListData: function() {
        var t = this;
        this.initData();
        var e = this.data, o = e.titleArr, r = e.active, n = e.page, s = e.location, d = {
            code: o[r].code,
            page: n,
            longitude: s.longitude,
            latitude: s.latitude
        }, l = i.getNetAddresss("plugin.live-install.frontend.worker-order.orderList");
        i._postNetWork({
            url: l,
            data: d,
            success: function(e) {
                var o = e.data;
                if (1 != o.result) return i.tips(o.msg);
                t.data.total_page = o.data.last_page, t.data.total_page || (t.data.total_page = 0), 
                o.data.another_name && o.data.another_name.worker_name && wx.setNavigationBarTitle({
                    title: o.data.another_name.worker_name
                }), t.setData({
                    listData: o.data.data,
                    networkLoading: !0,
                    custom_name: o.data.another_name.custom_name || "安装"
                }), t.data.titleArr.forEach(function(e, i) {
                    "waitInstall" == e.code && t.setData(a({}, "titleArr[" + i + "].name", "待".concat(t.data.custom_name, "订单")));
                }), console.log(o);
            }
        });
    },
    _getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page += 1;
            var e = this.data, a = e.titleArr, o = e.active, r = e.page, n = e.location, s = {
                code: a[o].code,
                page: r,
                longitude: n.longitude,
                latitude: n.latitude
            }, d = i.getNetAddresss("plugin.live-install.frontend.worker-order.orderList");
            i._postNetWork({
                url: d,
                data: s,
                success: function(e) {
                    var a = e.data;
                    if (t.data.isLoadMore = !0, 1 === a.result) {
                        var i = t.data.listData.concat(a.data.data);
                        t.setData({
                            listData: i
                        });
                    } else t.data.page = t.data.page - 1, t.data.isLoadMore = !1;
                }
            });
        }
    },
    bindBtnClick: function(a) {
        var o = this;
        return e(t.default.mark(function e() {
            var r, n, s, d, l;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    if (console.log(a), r = a.currentTarget.dataset, n = r.index, s = r.btn, d = r.order_id, 
                    o.data._order_id = d, console.log(s), "installStart" != s.code && "finishRefund" != s.code && "installStart" != s.code) {
                        t.next = 12;
                        break;
                    }
                    return t.next = 7, i.confirm("确定".concat(s.name, "?"));

                  case 7:
                    if (0 != t.sent) {
                        t.next = 10;
                        break;
                    }
                    return t.abrupt("return");

                  case 10:
                    t.next = 18;
                    break;

                  case 12:
                    if ("workerChoose" != s.code) {
                        t.next = 18;
                        break;
                    }
                    return t.next = 15, i.confirm("确定抢单吗？");

                  case 15:
                    if (0 != t.sent) {
                        t.next = 18;
                        break;
                    }
                    return t.abrupt("return");

                  case 18:
                    if ("stateRefunding" != s.code && "stateRefunded" != s.code) {
                        t.next = 20;
                        break;
                    }
                    return t.abrupt("return");

                  case 20:
                    if ("installFinish" != s.code) {
                        t.next = 23;
                        break;
                    }
                    return o.setPictureShow(), t.abrupt("return");

                  case 23:
                    l = i.getNetAddresss(s.api), i._postNetWork({
                        url: l,
                        data: {
                            order_id: d,
                            source: 2
                        },
                        success: function(t) {
                            var e = t.data;
                            if (1 !== e.result) return i.tips(e.msg);
                            if ("workerChoose" == s.code) {
                                i.tips(e.msg);
                                var a = o.data.listData;
                                a.splice(n, 1), o.setData({
                                    listData: a
                                });
                            } else if ("takeCode" == s.code || "payCode" == s.code) {
                                var r = "takeCode" == s.code ? "取货码" : "收款码";
                                o.setData({
                                    takeCodeImageUrl: e.data,
                                    codeShow: !0,
                                    codeText: r
                                });
                            } else "installStart" == s.code && o.getListData();
                        }
                    });

                  case 25:
                  case "end":
                    return t.stop();
                }
            }, e);
        }))();
    },
    sendImageBtn: function() {
        var t = this, e = this.data, a = e.pictureList, o = e._order_id;
        if (0 == a.length) return i.tips("请上传安装图片");
        var r = i.getNetAddresss("plugin.live-install.frontend.worker-order.finishInstall");
        i._postNetWork({
            url: r,
            data: {
                order_id: o,
                image: a
            },
            success: function(e) {
                var a = e.data;
                if (1 !== a.result) return i.tips(a.msg);
                t.setPictureShow(), t.setData({
                    active: 5
                }), t.getListData();
            }
        });
    },
    gotoDetails: function(t) {
        var e = t.currentTarget.dataset.order_id;
        wx.navigateTo({
            url: "/packageH/installationSever/installationSeverDetail/installationSeverDetail?order_id=" + e
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    bindChangeActive: function(t) {
        this.setData({
            active: t.detail.index
        }), this.getListData();
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onRead_2: function() {
        var t = this;
        wx.chooseImage({
            count: 9,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(e) {
                console.log(e.tempFilePaths), t.unload({
                    tempFilePaths: e.tempFilePaths
                });
            }
        });
    },
    unload: function(t) {
        var e = this;
        if (0 != t.tempFilePaths.length) {
            wx.showLoading({
                title: "上传中"
            });
            var a = i.getNetAddresss("upload.uploadPic");
            wx.uploadFile({
                url: a,
                filePath: t.tempFilePaths[0],
                name: "file",
                formData: null,
                success: function(t) {
                    var a = JSON.parse(t.data), i = e.data.pictureList;
                    i.push(a.data.img_url), e.setData({
                        pictureList: i
                    });
                },
                complete: function(a) {
                    wx.hideLoading(), t.tempFilePaths.shift(), e.unload(t);
                }
            });
        }
    },
    onShareAppMessage: function() {}
});